﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Utils
{
    public static class EnumUtils
    {
        /// <summary>
        /// Get name of resource of a property. Resource is an attribute that's tag a property.
        /// e.g. IconProperties.Icon
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public static string GetResourceName(object property, bool fullQualifiedName = true)
        {
            if (!fullQualifiedName)
                return property.ToString();

            if (DecoratorExtension.IsMetadata(property) ||
                DecoratorExtension.IsWebResource(property) ||
                DecoratorExtension.IsAction(property)
                )
                return DecoratorExtension.getAlias(property);

            return EnumUtils.GetFullName(property);
        }

        public static EntryListTypes GetEntryListType(string typeStr)
        {
            EntryListTypes elType = EntryListTypes.Unknown;
            if (EnumUtils<EntryListTypes>.EnumTryParse(typeStr, out elType))
                return elType;
            return EntryListTypes.Unknown;
        }

        /// <summary>
        /// Get full name of a property
        /// </summary>
        /// <param name="enumItem"></param>
        /// <returns></returns>
        public static string GetFullName(object enumItem)
        {
            return String.Format("{0}.{1}", enumItem.GetType().Name, enumItem.ToString());
        }

        public static string GetPropertyName(object enumItem)
        {
            return enumItem.ToString();            
        }

     
    }
}
